import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:xiongan_app_yy/entrys/rp/to_review_entity.dart';
import 'package:xiongan_app_yy/pages/common/BaseMaterialInfo.dart';
import 'package:xiongan_app_yy/pages/common/TextFieldItem.dart';
import 'package:xiongan_app_yy/pages/common/TextItemCard.dart';
import 'package:xiongan_app_yy/provider/toreview_provider.dart';
import 'package:xiongan_app_yy/utils/ImageDetailsUtils.dart';
import 'package:xiongan_app_yy/utils/image_utils.dart';
import 'package:xiongan_app_yy/widgets/comm/left_icon_widget.dart';

class ToReviewDetail extends StatefulWidget {
  int index;

  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _ToReviewDetail();
  }

  ToReviewDetail(this.index);
}

class _ToReviewDetail extends State<ToReviewDetail> {
  List mList = List();
  ToReviewData bean = ToReviewData();
  String image = "assets/images/build.png";
  TextEditingController controller0 = TextEditingController();
  bool state = true;
  int into = 0;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    mList = Provider.of<ToReviewProvider>(context).detailListData.datas;
    bean = mList[widget.index];
    if (bean.imageurl != null && image == "assets/images/build.png") {
      ImageDownloadUtil.getImageBase64(bean.imageurl, (im) {
        setState(() {
          image = im;
        });
      });
    }
    if (bean.ischeck == true) {
      state = false;
      controller0.text = bean.checkquantity.toString();
    }
    if (into == 0) {
      controller0.text =
          bean.checkquantity != 0 ? bean.checkquantity.toString() : "";
      into++;
    }

    return Scaffold(
      appBar: AppBar(
        leading: LeftIconWidget(icon: Icons.chevron_left, isize: 36),
        backgroundColor: Color(0XFF00A5F1),
        title: Text(
          "复核详情",
          style: TextStyle(fontSize: 18),
        ),
        elevation: 0,
        centerTitle: true,
      ),
      body: Column(
        children: <Widget>[
          Expanded(
            child: Scrollbar(
              child: SingleChildScrollView(
                child: Column(
                  children: <Widget>[
                    TextItemCard(
                      name: "托盘码",
                      value: bean.worktoolcode ?? "暂无",
                    ),
                    TextItemCard(
                      name: "库区",
                      value: bean.areaname ?? "暂无",
                    ),
                    TextItemCard(
                      name: "货架",
                      value: bean.shelfname ?? "暂无",
                    ),
                    TextItemCard(
                      name: "货位",
                      value: bean.locationcode ?? "暂无",
                    ),
                    Column(
                      children: <Widget>[
                        BaseMaterialInfo(
                          imgwid: GestureDetector(
                            child: ImageDownloadUtil.isImageType(image),
                            onTap: () {
                              ImageDetailsUtils.jumpImageDetails(
                                  context, image, false);
                            },
                          ),
                          options: {
                            "materialname": "物资名称",
                            "materialcode": "实物ID",
                            "baseunitname": "基本单位",
                            "quantity": "计划复核数"
                          },
                          data: bean.toJson(),
                        ),
                        Container(
                          padding: EdgeInsets.all(15),
                          child: Column(
                            children: <Widget>[
                              TextFieldItem(
                                  enabled: state,
                                  textEditingController: controller0,
                                  hintText: "输入实际复核数")
                            ],
                          ),
                        )
                      ],
                    )
                  ],
                ),
              ),
            ),
          ),
          Offstage(
            offstage: !state,
            child: Row(
              children: <Widget>[
                Expanded(
                  child: FlatButton(
                    shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.all(Radius.circular(0))),
                    padding: EdgeInsets.all(15),
                    color: Color(0xFF42AFF0),
                    child: Text(
                      "确认",
                      style: TextStyle(color: Colors.white),
                    ),
                    onPressed: () {
                      bean.checkquantity = controller0.text;
                      Navigator.pop(context);
                    },
                  ),
                )
              ],
            ),
          )
        ],
      ),
    );
  }
}
